/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate.entityes;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author eleven
 */
@Entity
@Table(name = "distance")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Distance.findAll", query = "SELECT d FROM Distance d"),
    @NamedQuery(name = "Distance.findByFromcity", query = "SELECT d FROM Distance d WHERE d.distancePK.fromcity = :fromcity"),
    @NamedQuery(name = "Distance.findByTocity", query = "SELECT d FROM Distance d WHERE d.distancePK.tocity = :tocity"),
    @NamedQuery(name = "Distance.findByFromCityAndToCity", query = "SELECT d FROM Distance d WHERE (d.distancePK.fromcity = :fromcity) and (d.distancePK.tocity = :tocity)"),
    @NamedQuery(name = "Distance.findByDistance", query = "SELECT d FROM Distance d WHERE d.distance = :distance")})
public class Distance implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DistancePK distancePK;
    @Basic(optional = false)
    @Column(name = "DISTANCE")
    private double distance;

    public Distance() {
    }

    public Distance(DistancePK distancePK) {
        this.distancePK = distancePK;
    }

    public Distance(DistancePK distancePK, double distance) {
        this.distancePK = distancePK;
        this.distance = distance;
    }

    public Distance(String fromcity, String tocity) {
        this.distancePK = new DistancePK(fromcity, tocity);
    }

    public DistancePK getDistancePK() {
        return distancePK;
    }

    public void setDistancePK(DistancePK distancePK) {
        this.distancePK = distancePK;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (distancePK != null ? distancePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Distance)) {
            return false;
        }
        Distance other = (Distance) object;
        if ((this.distancePK == null && other.distancePK != null) || (this.distancePK != null && !this.distancePK.equals(other.distancePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hibernate.entityes.Distance[ distancePK=" + distancePK + " ]";
    }
}
